package cn.wolfcode.restful.controller;


import cn.wolfcode.restful.domain.Employee;
import cn.wolfcode.restful.domain.User;
import cn.wolfcode.restful.util.JsonResult;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;

@RestController
public class HomeWordController {

    /**需求:用户登录/注销   --- 定义出接口即可
     * 1>请求路径--/user/{username}/{password}
     * 2>请求方式--GET
     * 3>请求参数--username--password
     * 4>请求响应--验证以后的状态
     */
    @RequestMapping("/user/{username}/{password}")
    public JsonResult login(User user){
        //假装去数据库进行数据查询
        if ("tf".equals(user.getUsername()) && "1".equals(user.getPassword())) {
            return JsonResult.success("登录成功");
        }
        return JsonResult.success("登录失败");
    }

    /**需求：查询某个员工所有工资信息
     * 1.请求路径--/employees/{eid}--
     * 2.请求方式--GET--查询
     * 3.请求参数--id--
     * 4.请求响应--所有的工资信息
     */
    @RequestMapping("/employees/detail/{eid}")
    public Employee get(@PathVariable("eid") Long id){
        //假装去数据库去查询信息
        Employee employee = new Employee();
        employee.setId(id);
        employee.setName("罗嘉颖");
        employee.setAge(25);
        employee.setSalary(new BigDecimal("15000"));
        return employee;
    }

    /**需求：查询某个员工某个月工资信息
     * 1>请求路径--/employee/{eid}/{month}
     * 2>请求方式--GET
     * 3>请求参数--id,month
     * 4>请求响应--
     */
    @RequestMapping(value = "/employees/{eid}/{month}",method = RequestMethod.GET)
    public Employee selectByEmployeeId(@PathVariable("eid") Long id, @PathVariable Integer month){

        Employee employee = new Employee();
        employee.setId(id);
        employee.setAge(18);
        employee.setName("罗嘉颖");
        employee.setSalary(new BigDecimal("15000"));

        //假装去数据库进行查询
        return  employee;
    }


    /**需求：查询某个部门所有员工
     * 1.请求路径--查询所有员工--/employees/selectAll
     * 2.请求方式--查询--GET
     * 3.请求参数--部门id
     * 4.请求响应--员工集合--list
     */
    @RequestMapping(value = "/employees/selectAll/{id}",method = RequestMethod.GET)
    public List<Employee> selectAll(Long id){
        List<Employee> list =  Arrays.asList(new Employee(1L,"罗嘉颖",25)
                ,new Employee(2L,"梁特芳",22));
        return list;
    }


    /**需求：查询某个部门某个员工信息
     *1.请求路径--查询--/employees/{id}/{deptId}
     *2.请求方式--查询-GET
     *3.请求参数--部门id--员工id
     *4.请求响应--员工对象
     */
    @RequestMapping(value = "/employees/selectByEmployeeIdAndDepartment/{id}/{deptId}",method = RequestMethod.GET)
    public Employee selectByEmployeeIdAndDepartment(@PathVariable Long id,@PathVariable Long deptId){

        //根据传入的员工id和部门id去数据库查询数据
        return new Employee(403L,"罗嘉颖",25);
    }


    /**查询某个部门所有员工工资和
     * 1.请求路径--/employees/selectByDepartmentId
     * 2.请求方式--GET--查询
     * 3.请求参数--部门id
     * 4.请求响应--部门工资总和
     */
    @RequestMapping(value = "/employees/selectByDepartmentId",method = RequestMethod.GET)
    public BigDecimal selectByDepartmentId(Long id){
        System.out.println(id);
        return new BigDecimal("250000");
    }
}
